<template>
  <!-- 选择病历模板 -->
  <el-drawer title="选择病历模板" size="600px" :visible="value" custom-class="drawer-box" :wrapperClosable="false" :destroy-on-close="true" @open="onOpen" @close="onClose" :append-to-body="true">
    <div class="p-sm" style="padding-bottom:0;">
      <el-form :inline="true" ref="form" @submit.native.prevent="getData(-1)">
        <el-form-item prop="name">
          <el-input v-model="form.name" placeholder="模板名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit" circle icon="el-icon-search"></el-button>
        </el-form-item>
      </el-form>
    </div>
    <table class="table-box" v-loading="loading">
      <thead>
        <tr>
          <th>模板名称</th>
          <th>模板类型</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index" @click="onClickItem(item)">
          <td>{{item.templateName}}</td>
          <td>{{item.templateRefType}}</td>
        </tr>
      </tbody>
    </table>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br>
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <br>
  </el-drawer>
</template>
<script>
export default {
  props: ["value", "doctorId", "deptId"],
  components: {
  },
  data() {
    return {
      pager: { pageSize: 15, pageNum: 1, total: 0 },
      tableList: [],
      loading: false,
      typeArr: [],
      form: {
        name: "",
        templateType: 1,
        doctorId: "",
        deptId: ""
      }
    };
  },
  created() {
    let th = this;
  },
  mounted() {
    let th = this;
    th.getCommonConfigByKey("模板类型").then(res => {
      th.typeArr = res;
    });
  },
  methods: {
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      th.loading = true;
      th.$api.templateDynamicpageQueryDoctorUse(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
        th.loading = false;
      });
    },
    //点击之后
    onClickItem(obj) {
      let th = this;
      th.loading = true;
      th.$api.getidtemplateDynamic({ id: obj.id }).then(res => {
        if (res.executed) {
          th.$emit("success", {id:res.data.id,templateDynamicFieldBeans:res.data.templateDynamicFieldBeans });
          th.onClose();
        }
        th.loading = false;
      });
    },
    onOpen() {
      let th = this;
      th.form.doctorId = th.doctorId;
      th.form.deptId = th.deptId;
      th.$nextTick(function() {
        th.getData();
      });
    },
    onClose() {
      let th = this;
      th.$refs["form"].resetFields();
      th.$emit("input", false);
    }
  }
};
</script>
